<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="上报人姓名" name="userName">
						<a-input v-model:value="searchFormState.userName" placeholder="请输入上报人姓名" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="上报人电话" name="userPhone">
						<a-input v-model:value="searchFormState.userPhone" placeholder="请输入上报人电话" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="隐患类型" name="hiddenType">
						<a-select v-model:value="searchFormState.hiddenType" placeholder="请选择隐患类型" :options="hiddenTypeOptions" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="隐患等级" name="hiddenLevel">
						<a-select v-model:value="searchFormState.hiddenLevel" placeholder="请选择隐患等级" :options="hiddenLevelOptions" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="上报日期" name="reportDate">
						<a-range-picker v-model:value="searchFormState.reportDate" value-format="YYYY-MM-DD"/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="核实日期" name="verifyDate">
						<a-range-picker v-model:value="searchFormState.verifyDate" value-format="YYYY-MM-DD"/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="table.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.reportId"
			:tool-config="toolConfig"
			:scroll="{ x: 1200,y:500 }"
		>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'hiddenType'">
					{{ $TOOL.dictTypeData('hiddenType', record.hiddenType) }}
				</template>
				<template v-if="column.dataIndex === 'hiddenLevel'">
					<a-tag color="green" v-if="record.hiddenLevel==0">一般问题</a-tag>
					<a-tag color="blue" v-if="record.hiddenLevel==1">一般隐患</a-tag>
					<a-tag color="orange" v-if="record.hiddenLevel==2">较大隐患</a-tag>
					<a-tag color="red" v-if="record.hiddenLevel==3">重大隐患</a-tag>
				</template>
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="viewFormRef.onOpen(record)">查看详情</a>
						<a-divider type="vertical" />
						<a @click="formRef.onOpen(record)">发放奖励</a>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="table.refresh(true)" />
	<ViewForm ref="viewFormRef" />
</template>

<script setup name="hiddenreport">
	import tool from '@/utils/tool'
	import Form from './form.vue'
	import ViewForm from '@/views/biz/hiddenreport/view.vue'
	import hiddenReportApi from '@/api/biz/hidden/hiddenReportApi'
	let searchFormState = reactive({})
	const searchFormRef = ref()
	const table = ref()
	const formRef = ref()
	const viewFormRef = ref()
	const hiddenTypeOptions = tool.dictList('hiddenType')
	const hiddenLevelOptions = tool.dictList('hiddenLevel')

	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '上报人姓名',
			dataIndex: 'userName',
			width: 100,
			align:'center'
		},
		{
			title: '上报人电话',
			dataIndex: 'userPhone',
			width: 120,
			align:'center'
		},
		{
			title: '上报时间',
			dataIndex: 'createTime',
			width: 180,
			align:'center'
		},
		{
			title: '隐患类型',
			dataIndex: 'hiddenType',
			align:'center'
		},
		{
			title: '隐患等级',
			dataIndex: 'hiddenLevel',
			align:'center'
		},
		{
			title: '建议奖励金额',
			dataIndex: 'suggestionRewards',
			align:'center'
		},
		{
			title: '核实人姓名',
			dataIndex: 'verifyUserName',
			align:'center'
		},
		{
			title: '核实时间',
			dataIndex: 'verifyTime',
			width: 180,
			align:'center'
		},
		{
			title: '隐患具体地址',
			dataIndex: 'hiddenAddr',
			width: 220,
			align:'center'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: '240px'
		},
	]

	const loadData = (parameter) => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		if (searchFormParam.reportDate) {
			searchFormParam.reportDateStart = searchFormParam.reportDate[0]
			searchFormParam.reportDateEnd = searchFormParam.reportDate[1]
			delete searchFormParam.reportDate
		}
		if (searchFormParam.verifyDate) {
			searchFormParam.verifyDateStart = searchFormParam.verifyDate[0]
			searchFormParam.verifyDateEnd = searchFormParam.verifyDate[1]
			delete searchFormParam.verifyDate
		}
		searchFormParam.currentStatus = 2
		return hiddenReportApi.hiddenReportPage(Object.assign(parameter, searchFormParam)).then((data) => {
			return data
		})
	}
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		table.value.refresh(true)
	}
</script>
